﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameObjectsAndEquipment;

namespace StateMachine.GameStates
{
    public class SplashScreenState : GameState
    {
        private Sprite sprite;
        private TextObject pressText;
        private SpriteFont font;

        public SplashScreenState(int screenWidth, int screenHeight)
            :base(screenWidth,screenHeight)
        {

        }

        public override void LoadContent(ContentManager content)
        {
            base.LoadContent(content);

            font = content.Load<SpriteFont>("basic");

            sprite = new Sprite(new Vector2(0,0), content.Load<Texture2D>("logo"));
            sprite.X = screenWidth / 2 - sprite.Width / 2;
            sprite.Y = screenHeight / 2 - sprite.Height / 2;

            pressText = new TextObject( new Vector2(0,0), 
                                        "Press SPACE", font, Color.White);
            pressText.X = screenWidth / 2 - pressText.Width / 2;
            pressText.Y = sprite.Y + sprite.Height + 10;
        }

        public override void HandleInput(GameStateManager manager, GameTime gameTime)
        {
            KeyboardState newState = Keyboard.GetState();

            if (newState.IsKeyDown(Keys.Space))
            {
                if (!oldState.IsKeyDown(Keys.Space))
                {
                    manager.ChangeState(new MainMenuState(screenWidth, screenHeight));
                }
            }
        }

        public override void Update(GameStateManager manager, GameTime gameTime)
        {
            HandleInput(manager, gameTime);
            sprite.Update(gameTime);
        }

        public override void Draw(GameStateManager manager, GameTime gameTime)
        {
            manager.Renderer.ClearScreen(Color.Black);
            manager.Renderer.DrawSprite(sprite);
            manager.Renderer.DrawText(pressText,font);
        }
    }
}
